import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.io.*;

public class Test01 {
	public static void main(String[] args) {
		// 得到绝对路径
		String path = Test01.class.getClassLoader().getResource("per.json").getPath();
		// 调用写的方法
		String str = readJsonFile(path);

		JSONObject obj = JSON.parseObject(str);

		System.out.println(obj.get("name"));
		System.out.println(obj.get("age"));

	}

//读取json文件
	public static String readJsonFile(String fileName) {
		String jsonStr = "";
		try {
			File jsonFile = new File(fileName);
			FileReader fileReader = new FileReader(jsonFile);
			Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8");
			int ch = 0;
			StringBuffer sb = new StringBuffer();
			while ((ch = reader.read()) != -1) {
				sb.append((char) ch);
			}
			fileReader.close();
			reader.close();
			jsonStr = sb.toString();
			return jsonStr;
		} catch (IOException e) {
			e.printStackTrace();
			return null;

		}
	}
}
